﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TF.Access;

using log4net;

public partial class EditEmail : System.Web.UI.Page
{
    private static readonly ILog log = LogManager.GetLogger(typeof(EditEmail));
    protected string oldEmail;
    protected string existEmail;
    protected void Page_Load(object sender, EventArgs e)
    {

        TF_UserProfile up = WebUtility.GetUserProfile();
        if (!IsPostBack)
        {
            if (up != null)
            {
                ViewState["OldEmail"] = up.Email;
            }
        }
        else
        {
            try
            {
                up.Email = Request.Form["txtEmail"];
                if (TF_UserProfile.UserProfileRegCheck(up) != 0)
                {
                    up.Update();
                    this.ClientScript.RegisterStartupScript(typeof(EditEmail), "updatesucc", "<script>alert('更新成功!');</script>");
                    if (up != null)
                    {
                        oldEmail = up.Email;
                        ViewState["OldEmail"] = up.Email;
                    }
                }
                else
                {
                    this.ClientScript.RegisterStartupScript(typeof(EditEmail), "duplicateemail", "<script>alert('系统中已有该Email!');</script>");
                    existEmail = up.Email;
                    up.Email = ViewState["OldEmail"] as string;
                    
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                this.ClientScript.RegisterStartupScript(typeof(EditEmail), "updatefail", "<script>alert('更新失败!');</script>");
            }

        }

        if (up != null)
        {
            oldEmail = up.Email;
        }

    }
}
